<html>
	<head>
		<?php
			echo '<script>';
			echo 'function verifyUser(){';
			echo 'var provided = "'. $_GET["user"] . '";';
			echo 'var login = sessionStorage.getItem("user");';
			//echo 'alert (provided);';
			//echo 'alert (login);';
			echo 'if (login != provided){';
			echo 'window.location = "/index.html"';
			echo '}}';
			echo '</script>';
		?>
		<meta content "text/html; charset=utf-8" http-equiv="Content-Type">
		<title>Share My ToDo</title>
		<link rel="stylesheet" type="text/css" href="css/home.css" />
		<script src = "js/geo.js"></script>
	</head>
	<body>
	<section>
		<a class="hiddenanchor" id="showCreate"></a>
		<a class="hiddenanchor" id="hideCreate"></a>
		<div id="fade"></div>
		<header>
			<?php 
			echo "<h1>" . $_GET["user"] . "'s ToDo</h1>";
			?>
			<a id = "logout" href="/index.html" onclick="sessionStorage.clear();">Logout</a></br><br/>
		</header>
		<nav>
			<ul id="tabs">
				<li id="home" class="active">Home</li>
				<li><a href = "#showCreate">Create</a></li>
				<?php
					echo '<li><a href="view.php?user='.$_GET["user"].'">View&nbsp;All</a></li>';
					echo '<li><a href="delete.php?user='.$_GET["user"].'">Delete</a></li>';
					echo '<li id="profile"><a href="profile.php?user='.$_GET["user"].'">Profile</a></li>';
					echo '<li><a href="shared.php?user='.$_GET["user"].'">Shared</a></li>';
				?>
			</ul>
		</nav>
		<article id = "main">
			<section id="title">
				<h2> Recent Tasks</h2>
			</section>
			<section id="list">
			<?php
				$link = mysql_connect('localhost','cs4350','!@'); 
				if (!$link) { 
					die('Could not connect to MySQL: ' . mysql_error()); 
				}
				if (!mysql_select_db('todo', $link)) {
					die('Aw snap, no database named todo...');
				}
				
				$sql = 'SELECT * FROM list WHERE createDate >= DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND user="'.$_GET["user"].'"';
				$result = mysql_query($sql, $link);
				
				if (!$result) {
					die($sql);
				}
				while ($row = mysql_fetch_array($result)){
					if ($row['done']){
						echo '<input type="checkbox" checked="checked" disabled="disabled" />&nbsp&nbsp' . $row['taskName'];
					} else {
						echo '<input type="checkbox" onclick="location.href=\'done.php?user=' . $_GET["user"] . '&task=' . $row['taskID'] .'\'" />&nbsp&nbsp' . $row['taskName'];
					}
					echo '<br/>';
				}
				mysql_close($link);
			?>
			</section>
		</article>
		<div id="create">
			<form action = "create.php" method = "post" class = "straight">
				<label for = "taskName">Task Name:</label>
					<input class="textbox" type="text" name="taskName" required="required"/><br/><br/>
				<label for = "taskDesc">Task Descrpition:</label><br/>
					<textarea class="textbox" name="taskDesc"; rows="5" cols="30" maxlength="250" /></textarea></br>
				<div id="local" class="small"></div>
				<input type="submit" value="Create" name="create" class="button" />
				<a href = "#hideCreate" class = "closeDialog"><input type="button" value="Cancel" name="cancel" class="button" /></a>
				<?php
					echo '<input type="hidden" value=' . $_GET["user"] . ' name="username" />';
				?>
			</form>
		</div>
	</section>
	</body>
</html>